package com.buka.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class GatewayConfig {

    @Resource
    CustomRoutePredicateFactory customRoutePredicateFactory;

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(r -> r.path("/order/**")
                        .and().predicate(customRoutePredicateFactory.apply(new CustomRoutePredicateFactory.Config()))
                        .uri("lb://nacos-order"))
                .build();
    }
}